<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>USERS IMPORT</title>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#uploadForm').submit(function (event) {
                event.preventDefault();

                var formData = new FormData();
                formData.append('file', $('#userImage')[0].files[0]);

                $.ajax({
                    url: '/import',
                    type: 'POST',
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (response) {
                        // 处理成功响应
                        console.log(response);
                        $('.bd').html('<p>' + response + '</p>');
                    },
                    error: function (xhr, status, error) {
                        // 处理失败响应
                        console.error(xhr.responseText);
                        $('.bd').html('<p>' + xhr.responseText + '</p>');
                    }
                });
            });
        });
    </script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .box {
            margin: 80px auto;
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
        }

        .box1 {

            width: 1000px;
            height: 50px;
            background-color: #ededed;
            border-style: solid;
            border-width: 1px 1px 0px 1px;
            border-color: black;
        }

        .box1 p {
            display: inline-block;
            font-size: 15px;
            margin: 15px 30px;
        }

        .box1 input {
            display: inline-block;
            position: relative;
            left: 860px;
        }

        .box2 {
            width: 1000px;
            height: 500px;
            border-style: solid;
            border-width: 0px 1px 1px 1px;
            border-color: black;
        }

        .hd {
            margin: 50px auto;
        }

        .hd label {
            margin-left: 90px;
        }

        .hd input {
            margin-left: 20px;
        }

        .hd input:nth-of-type(1) {
            width: 440px;
            height: 40px;
        }

        .hd input:nth-of-type(3),
        :nth-of-type(4) {
            margin-left: 40px;
            width: 110px;
            height: 40px;
            background-color: #fff;
            border: 1px solid;
            border-radius: 5%;
        }

        .bd input {
            margin: 60px auto;
            width: 860px;
            height: 300px;
            display: flex;
            justify-content: center;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box1">
            <p>用户导入</p>
            <a href="Menu.html"><input type="button" name="close" value="X" /></a>
        </div>
        <div class="box2">
            <div class="hd">
                <form id="uploadForm"  enctype="multipart/form-data">
                    <label for="inputFiled">文件：</label>
                    <input type="text" id="inputFiled" name="file">
                    <input type="text" name="user" id="user">
                    <input type="file" name="userImage" id="userImage" style="display: none;">
                    <input type="button" id="" value="浏览" onclick="document.getElementById('userImage').click()">
                    <input type="submit" name="sub" value="开始导入">
                </form>
            </div>
            <div class="bd">
                <input type="text">
            </div>
        </div>

    </div>
</body>

</html>